package com.cfc.stage1;

import org.junit.Test;

/**
 * @description: 面试题 17.16. 按摩师
 *     TODO 这个貌似用到了动态规划呢呀，后续在回过头来看一下吧
 *     https://leetcode.cn/problems/the-masseuse-lcci/
 * @author: yangxuan10
 * @create: 2024-05-20 13:29
 **/
public class Massage {

    @Test
    public void test1() {

        // [1,4,5,3,1]
        // [2,1,4,5,3,1]
        // [2,2,1,4,5,3,1]

        //一步一步迭代优化呗，哪能一口吃一个胖子呀

        String str = "1,4,5,3,1";
        String[] split = str.split(",");

        int maxSum = 0;
        for (int i = 0; i < split.length; i++) {
            String s = split[i];

        }
    }

    public int massage(int[] nums) {
        int n = nums.length;
        if (n == 0) {
            return 0;
        }
        int dp0 = 0, dp1 = nums[0];

        for (int i = 1; i < n; ++i) {
            int tdp0 = Math.max(dp0, dp1); // 计算 dp[i][0]
            int tdp1 = dp0 + nums[i]; // 计算 dp[i][1]

            dp0 = tdp0; // 用 dp[i][0] 更新 dp_0
            dp1 = tdp1; // 用 dp[i][1] 更新 dp_1
        }
        return Math.max(dp0, dp1);
    }
}